<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript">
<!-- 
$(function(){
	//数据列表
	var dg = $("#mgr_unit_dg").datagrid({
		url:"${pageContext.request.contextPath}/mgr/unit!datagrid.action",
		fit:true,
		fitColumns:true,
		pagination:true,
		pagePosition:"bottom",
		pageSize:20,
		pageList:[20,30,40],
		border:false,
		idField:"id",
		sortName:"name",
		sortOrder:"asc",
		columns:[[{
			field:"id",
			checkbox:true
		},{
			title:"学校单位代码",
			field:"code",
			width:64,
			sortable:true
		},{
			title:"学校单位名称",
			field:"name",
			width:128,
			sortable:true
		},{
			title:"学校单位类型",
			field:"type",
			width:80,
			formatter:function(value,row,index){
				if(value == 0)
					return "未知";
				else if(value == 1)
					return "幼儿园";
				else if(value == 2)
					return "小学";
				else if(value == 3)
					return "初中";
				else if(value == 4)
					return "高中";
				else if(value == 5)
					return "职中";
				else if(value == 6)
					return "高职高专";
				else if(value == 7)
					return "大学";
				else 
					return "教育局";
			},
			sortable:true
		},{
			title:"学校单位地址",
			field:"address",
			width:168,
			sortable:true
		},{
			title:"学校单位网址",
			field:"website",
			width:168,
			sortable:true
		}]],
		toolbar:"#mgr_unit_dg_toolbar",
		onDblClickRow:function(rowIndex,rowData){
			mgr_unit_edit_window("编辑学校单位",rowIndex,rowData);
		}
	});
	//查询
	mgr_unit_dg_search = function(){
		dg.datagrid("load",{
			name:$("#mgr_unit_dg_toolbar input[type=text]").val()
		});
	};
	//新增
	mgr_unit_dg_add = function(){
		mgr_unit_edit_window("新增学校单位",0,null);
	};
	//删除
	mgr_unit_dg_delete = function(){
		var rows = dg.datagrid("getChecked");
		if(rows && rows.length > 0){
			$.messager.confirm("确认","您是否确认删除选中的数据?",function(r){
				if(!r)return;
				var ids = [];
				for(var i = 0; i < rows.length; i++){
					ids.push(rows[i].id);
				}
				$.ajax({
					url:"${pageContext.request.contextPath}/mgr/unit!delete.action",
					type:"POST",
					data:{
						id:ids.join("|")
					},
					dataType:"json",
					success:function(data,textStatus){
						if(data.success){
							dg.datagrid("load");
							dg.datagrid("unselectAll");
						}else{
							$.messager.show({
								title:"提示",
								msg:data.msg
							});
						}
					}
				});
			});
		}else{
			$.messager.alert("提示","未选中须删除的数据！");
		}
	};
	//
	function mgr_unit_edit_window(title,index,row){
		var d = $("<div/>").dialog({
			title:title,
			width:400,
			height:300,
			href:"${pageContext.request.contextPath}/mgr/unit!edit.action",
			modal:true,
			buttons:[{
				text:"保存",
				iconCls:"icon-save",
				handler:function(){
					$("#mgr_unitedit_form").form("submit",{
						url:"${pageContext.request.contextPath}/mgr/unit!update.action",
						success:function(data){
							var data = jQuery.parseJSON(data);
							if(data.success){
								dg.datagrid(row ? "updateRow" : "insertRow",{
									index:index,
									row:data.data
								});
								d.dialog("close");
							}else{
								$.messager.show({
									title:"保存异常",
									msg:data.msg
								});
							}
						}
					});
				}
			},{
				text:"关闭",
				iconCls:"icon-cancel",
				handler:function(){
					d.dialog("close");
				}
			}],
			onClose:function(){
				$(this).dialog("destroy");
			},
			onLoad:function(){
				if(row){
					$("#mgr_unitedit_form").form("load",row);
				}
			}
		});
	};
});
//-->
</script>
<table id="mgr_unit_dg"></table>
<div id="mgr_unit_dg_toolbar">
	<a href="#" class="easyui-linkbutton" onclick="mgr_unit_dg_add()" data-options="iconCls:'icon-add',plain:true" style="float:left;">新增</a>
	<div class="datagrid-btn-separator"></div>
	<a href="#" class="easyui-linkbutton" onclick="mgr_unit_dg_delete()" data-options="iconCls:'icon-remove',plain:true">删除</a>
	<div class="datagrid-btn-separator"></div>
	<span>学校单位:</span>
	<input type="text"  style="width:268px;"/>
	<a href="#" class="easyui-linkbutton" onclick="mgr_unit_dg_search()" data-options="iconCls:'icon-search',plain:true">查询</a>
</div>